﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using ModemGSM;

namespace PhoneManager
{
    public partial class frmAnalyze : PhoneManager.FrmDefault
    {
        private ModelATCommands ThisModelATCommands;
        public frmAnalyze()
        {
            InitializeComponent();
        }
        private void BntClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmAnalyze_Shown(object sender, EventArgs e)
        {
            Application.DoEvents();
            Analyser();
        }
        private void Analyser()
        {
            this.Cursor = Cursors.WaitCursor;
            BntRegister.Enabled = false;
            BntTry.Enabled = false;
            BntClose.Enabled = false;
            ThisModelATCommands = new ModelATCommands();
            foreach (Control item in PnlFrm.Controls)
            {
                if (item.Tag != null)
                {
                    if (item.Tag.ToString() == "CMD")
                    {
                        ((Label)item).Image = Properties.Resources.OnOffDisabled;
                    }
                }
            }
            ThisModelATCommands.ModelCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.Model);
            this.LblModel.Image = ThisModelATCommands.ModelCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.LineIdentificationCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.LineIdentification);
            this.LblLineInd.Image = ThisModelATCommands.LineIdentificationCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.IndicatorControlCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.IndicatorControl);
            this.LblIndic.Image = ThisModelATCommands.IndicatorControlCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.ActiveStatusCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.ActiveStatus);
            this.LblStatus.Image = ThisModelATCommands.ActiveStatusCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.PreferredOperatorCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.PrefOperator);
            this.LblOper.Image = ThisModelATCommands.PreferredOperatorCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SignalQualityCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.Sginal);
            this.LblSignal.Image = ThisModelATCommands.SignalQualityCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.CharSetsCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.ChatSet);
            this.LblChar.Image = ThisModelATCommands.CharSetsCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.PhoneBookCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.Phonebook);
            this.LblPhone.Image = ThisModelATCommands.PhoneBookCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.ClockCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.Clock);
            this.LblClock.Image = ThisModelATCommands.ClockCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.AlarmCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.Alarms);
            this.LblAlarms.Image = ThisModelATCommands.AlarmCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.BatteryLevelCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.Battery);
            this.LblBat.Image = ThisModelATCommands.BatteryLevelCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();


            ThisModelATCommands.SMSFormatCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSFormat);
            this.LblTextFormat.Image = ThisModelATCommands.SMSFormatCMD ? Properties.Resources.On : Properties.Resources.Off;
            if (ThisModelATCommands.SMSFormatCMD)
            {
                SharedLib.ModemGSM.SMSReadExistPDUFormat();
                ThisModelATCommands.SMSFormatCMD  = SharedLib.ModemGSM.SMSReadExistTextFormat();
                this.LblTextFormat.Image = ThisModelATCommands.SMSFormatCMD ? Properties.Resources.On : Properties.Resources.Off;
            }
            else
            {
                SharedLib.ModemGSM.ExistSMSPDU = false;
                SharedLib.ModemGSM.ExistSMSText = false;
            }
            Application.DoEvents();

            ThisModelATCommands.SMSStoragesCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSStorage);
            this.LblSto.Image = ThisModelATCommands.SMSStoragesCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSAdressServiceCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSAdress);
            this.LblAdress.Image = ThisModelATCommands.SMSAdressServiceCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSShowHeadCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSHeard);
            this.LblHead.Image = ThisModelATCommands.SMSShowHeadCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSConfigIndicationsCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSIndicator);
            this.LblSmsInd.Image = ThisModelATCommands.SMSConfigIndicationsCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSSaveSettingsCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSSaveSettings);
            this.LblSaveSet.Image = ThisModelATCommands.SMSSaveSettingsCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSRestoreSettingsCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSRestoreSettings);
            this.LblRestSet.Image = ThisModelATCommands.SMSRestoreSettingsCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSMessageServiceCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSMessageService);
            this.LblMsgServ.Image = ThisModelATCommands.SMSMessageServiceCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSBroadcastMessageCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSBroadcastMessage);
            this.LblBrodc.Image = ThisModelATCommands.SMSBroadcastMessageCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSListMessageCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSListMessage);
            this.LblListMsg.Image = ThisModelATCommands.SMSListMessageCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSReadMessageCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSReadMessage);
            this.LblReadmsg.Image = ThisModelATCommands.SMSReadMessageCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSSendMessageCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSSendMessage);
            this.LblSentMsg.Image = ThisModelATCommands.SMSSendMessageCMD? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSSendMessageStorageCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSSendMessageStorage);
            this.LblStoSent.Image = ThisModelATCommands.SMSSendMessageStorageCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSWriteMessageStorageCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSWriteMessageStorage);
            this.LblstoWri.Image = ThisModelATCommands.SMSWriteMessageStorageCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            ThisModelATCommands.SMSDeleteMessageStorageCMD = SharedLib.ModemGSM.AnaliseModemCommand(AnalyzerCMDEnum.SMSDeleteMessageStorage);
            this.LblStoDel.Image = ThisModelATCommands.SMSDeleteMessageStorageCMD ? Properties.Resources.On : Properties.Resources.Off;
            Application.DoEvents();

            this.Cursor = Cursors.Default;
            BntRegister.Enabled = true;
            BntTry.Enabled = true;
            BntClose.Enabled = true;

        }

        private void BntTry_Click(object sender, EventArgs e)
        {
            Analyser();
        }

        private void BntRegister_Click(object sender, EventArgs e)
        {
            string Filename = SharedLib.CreateNameRegisterPhone(SharedLib.ModemGSM.IMEI);
            SharedLib.SaveRegisterPhoneFileName(ThisModelATCommands, Filename);
            SharedLib.ModemGSM.SetValidsAtCommand(ThisModelATCommands);
            this.Close();
        }

    }
}
